package haolin.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import haolin.dao.ReplayDao;
import haolin.dao.TopicDao;
import haolin.dao.UserDao;
import haolin.entity.UserEntity;
import haolin.pojo.Replay;
import haolin.pojo.Topic;
import haolin.pojo.User;
import haolin.util.DateUtil;

@WebServlet(urlPatterns = "/user.do")
public class UserServlet extends HttpServlet{
	private UserDao userDao = new UserDao();
	private TopicDao topicDao = new TopicDao();
	private ReplayDao replayDao = new ReplayDao();
	
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		int uid = Integer.parseInt(req.getParameter("uid"));
		User user = userDao.getUserById(uid);
		
		List<Topic> topicList = topicDao.getTopicListByTuid(uid);
		List<Replay> replayList = replayDao.getReplayListByUid(uid);
		
		UserEntity userEntity = new UserEntity(user.getUsermname(), user.getUsericon(), DateUtil.getDateStr1(user.getRegtime()),
				topicList, replayList);
		
		req.setAttribute("user", userEntity);
		
		req.getRequestDispatcher("WEB-INF/user.jsp").forward(req, resp);
	}
}
